/*
 * Copyright (c)  2015~2020, xforceplus
 * All rights reserved.
 * Project:datacare-orm
 * Id: PageQueryFuntion.java   2020-10-10 21-13-19
 * Author: Evan
 */
package cn.datacare.orm.engine.function;

import cn.datacare.orm.query.PageQuery;
import org.beetl.core.Context;
import org.beetl.core.Function;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: 2015~2020
 * </p>
 * <p>
 * Company/Department: xforceplus
 * </p>
 *
 * @author Evan
 * <b>Creation Time:</b> 2020-10-10 21-13-19
 * @since V1.0
 */
public class PageQueryFunction implements Function {

    @Override
    public String call(Object[] paras, Context ctx) {
        Object o = ctx.getGlobal(PageQuery.PAGE_FLAG);
        if (o != null && o == Boolean.TRUE) {
            return "count(1)";

        } else {

            if (paras.length == 0) {
                return "*";
            } else {
                return (String) paras[0];
            }
        }


    }
}
